a = input() 
if len(a) != 4 or not a.isdigit(): 
    print(0) 
else: 
    mx = 0 
    for i in range(4): 
        for j in range(i + 1, 5): 
            number = int(a[i:j]) 
            prost = True 
            if number <= 1: 
                prost = False 
            else: 
                for k in range(2, int(number**0.5) + 1): 
                    if number % k == 0: 
                        prost = False 
                        break 
            if prost and number > mx: 
                mx = number
    print(mx)
